home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / russell / russell.lha / examples / lfib.r < prev    next >
Text File  |  1989-12-29  |  601b  |  24 lines

  1. (* compile memo.r first *)
  2. (* Must be compiled with rc -pL *)
  3.  
  4. # define impure var Void
  5.  
  6. let
  7.     tabsize == 30;
  8.  
  9.     (* Convert a recursive function from Short to Long to a memo-function *)
  10.     memo == func [f: func[val Short; impure] val Long; impure] {
  11.                 extern {"memo"} [f, func[x: val Short] {x % tabsize}, tabsize]
  12.             };
  13.  
  14.     fib == memo[func[ x: val Short; impure ] {
  15.                     if
  16.                         x < 2 ==> Long$1
  17.                     #   else ==> fib[ x-1 ] + fib[ x-2 ]
  18.                     fi
  19.                 }];
  20.  
  21. in
  22.     put[ fib[ 35 ] ]; put["\n"];
  23. ni
  24.